package com.example.springbootsfzy.controller.lishenao;

import com.example.springbootsfzy.domain.Consultants;
import com.example.springbootsfzy.service.lishenao.ConsultantsService;
import com.example.springbootsfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

//咨询师表
//操作人员:李深奥
//操作步骤:增删改查
@RestController
@CrossOrigin
public class ConsultantsController {
    @Autowired
    private ConsultantsService consultantsService;
    //获取所有咨询师表信息
    @GetMapping("/getconsultants")
    public R getAllConsultants(@RequestParam(defaultValue = "1") int pagenum, @RequestParam(defaultValue = "10") int pagesize) {
        return R.ok(consultantsService.selectAll(pagenum,pagesize));
    }
    //获取咨询师表信息根据id
    @GetMapping("/getconsultantsbyid")
    public R getConsultantsById(Long id) {
        return R.ok(consultantsService.selectByPrimaryKey(id));
    }
    @PostMapping("/getconsultantsActive")
    public R getConsultantsActive(@RequestBody Consultants consultants) {
//        System.out.println(consultants.getConsultantLevels().getLevelId());
//        System.out.println(consultants.getChargeStandardTypes().get(0).getTypeId());
        return R.ok(consultantsService.selectActive(consultants));
    }
    //增加咨询师表信息
    @PostMapping("/addconsultants")
    public R addConsultants(@RequestBody Consultants consultants) {
        int i = consultantsService.insert(consultants);
        if (i > 0) {
            return R.ok("添加成功");
        } else {
            return R.error("添加失败");
        }
    }

    //删除咨询师表信息
    @DeleteMapping("/delconsultants")
    public R deleteConsultants(Long id) {
        int i = consultantsService.deleteByPrimaryKey(id);
        if (i > 0) {
            return R.ok("删除成功");
        } else {
            return R.error("删除失败");
        }
    }

    //修改咨询师表信息
    @PutMapping ("/upconsultants")
    public R updateConsultants(@RequestBody Consultants consultants) {
        int i = consultantsService.updateByPrimaryKey(consultants);
        if (i > 0) {
            return R.ok("修改成功");
        } else {
            return R.error("修改失败");
        }
    }

    @GetMapping("/getAllConsultants")
    public R getAllConsultants(@RequestParam String username, @RequestParam String password) {
        Consultants consultants = consultantsService.selectByAccountAndPassword(username, password);
        if (consultants != null) {
            return R.ok(consultants);
        } else {
            return R.error("查询失败，未找到该咨询师");
        }
    }

}
